﻿using MxWeiXinPF.API.Payment.Tenpay;
using MxWeiXinPF.Common;
using MxWeiXinPF.Web.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MxWeiXinPF.Web.weixin.jiaoshuifei
{
    public partial class payment : WeiXinPage
    {
        string key = "";
        string wxusername = "";
        public List<Model.BindRecord> list = null;
        public int wid = 0;
        public string tel = "";
        public string apiurl = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            wid = MyCommFun.RequestWid();
            string thisUrl = MyCommFun.getWebSite() + "/weixin/jiaoshuifei/payment.aspx?wid=" + wid;
            OAuth2BaseProc(wid, thisUrl);


            if (wid == 0 || openid == "")
            {
                Response.Redirect("/weixin/jiaoshuifei/index.aspx?wid=" + wid);
            }
          

            BindList bindlistClass = new BindList();
            
            MxWeiXinPF.BLL.shuifei_baseinfo _baseInfoBLL = new BLL.shuifei_baseinfo();
            Model.shuifei_baseinfo baseinfoModel = _baseInfoBLL.GetModelByWid(Convert.ToInt32(wid));
            if (baseinfoModel != null)
            {
                wxusername = baseinfoModel.api_UserName;
                key = baseinfoModel.api_Key;
                tel = baseinfoModel.tel;
                apiurl = baseinfoModel.api_url;

            }
            string msg = string.Empty;
   
            list = bindlistClass.BindRecordList(wxusername, key, apiurl,openid, "", out msg);

            if (list == null || list.Count <= 0)
            {
                Response.Redirect("/weixin/jiaoshuifei/paymentnoone.aspx?wid=" + wid);

            }
            if (list != null && list.Count == 1)
            {
                Response.Redirect("/weixin/jiaoshuifei/baseinfo.aspx?wid=" + wid + "&consNo=" + list[0].consNo);
            }
        }
    }
}